
<div class="form">
<?php 
    Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/jquery.number_format.js", CClientScript::POS_END);
    $form=$this->beginWidget('CActiveForm', array(
            'id'=>'storage-detail-form',
            'enableAjaxValidation'=>false,
    )); 
    echo $this->renderFlash(); 
?>

        <table border="0" cellpadding="0" cellspacing="0"  id="id-form">  
            <tr>
                <td colspan="2">
                    <fieldset>
                        <legend>Income Material List</legend>
                        <table>
                            <tr>
                                <th style="min-width: 80px; width:80px; padding-left:10px">Create at:</th>
                                <td style="padding-left:10px"><?php echo date('d-m-Y'); ?></td>
                                <th style="min-width: 30px; width:30px; padding-left:10px">By:</th>
                                <td><?php echo "User Name" ?></td>
                            </tr>
                        </table>
                    </fieldset>
                </td>
            </tr>
            <tr>                
                <td colspan="2">
                    <div style="height: 500px">      
                        <ul style="list-style-type: none">
                            <?php
                            //load preset material in recipie detail
                            if (count($presetMaterial)):
                                foreach ($presetMaterial as $preset => $presetVal):
                                    $presetArray[$presetVal->material_id] = $presetVal->income_amount;
                                endforeach;
                            endif;

                            foreach ($materialList as $material => $value):
                                $preMaterialValue = 0;
                                if (isset($presetArray)):
                                    $preMaterialValue = $presetArray[$value->materialid];
                                endif;
                                echo CHtml::openTag('li', array('style' => 'width: 500px; float:left; line-height: 10px; margin: 5px'));
                                ?>
                                <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                    <?php
                                    echo CHtml::openTag('th', array('valign' => 'top', 'style' => 'width: 200px'));
                                    echo $value->materialname;
                                    echo CHtml::closeTag('th');
                                    echo CHtml::openTag('td');
                                    echo CHtml::textField('Material[income_amount][' . $value->materialid . ']', number_format($preMaterialValue, 0, '', ' '), array(
                                        'class' => 'inp-form',
                                        'onfocus' => '$(this).select()',
                                        'onkeyup' => '
                                                    var format_number = $().number_format($(this).val().replace(/\s/g, ""), {
                                                        numberOfDecimals:0,
                                                        decimalSeparator: ",",
                                                        thousandSeparator: " "
                                                    });

                                                    $(this).val(format_number);
                                                ',
                                    ));
                                    echo CHtml::label(menuService::getMaterialUnit($value->unitid), $value->unitid);                                
                                    echo CHtml::closeTag('td');
                                    ?>
                                </table>
                               <?php
                                echo CHtml::closeTag('li');
                            endforeach;
                            ?>
                        </ul>            
                    </div>

                </td>
                <td></td>
            </tr>
            <tr>
                <th>&nbsp;</th>
                <td valign="top">
                    <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('class' => 'form-submit')); ?>
                </td>
                <td></td>
            </tr>
        </table>
        
<?php $this->endWidget(); ?>

</div><!-- form -->
